local skill = fk.CreateSkill{
  name = "action__fugui_skill",
}

Fk:loadTranslationTable{
  ["action__fugui"] = "富贵",
  ["action__fugui_skill"] = "富贵",
  [":action__fugui"] = "锦囊牌<br /><b>时机</b>：出牌阶段<br /><b>目标</b>：你 <br /><b>效果</b>：选择一名其他角色，其下次获得手牌后，你摸等量张牌。（不可响应）",
  ["#action__fugui_skill"] = "选择一名其他角色，其下次获得手牌后，你摸等量张牌",
  ["@action__fugui"] = "富贵",
}


skill:addEffect("cardskill", {
  mute = true,
  prompt = "#action__fugui_skill",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return not player:isProhibited(player, card)
  end,
  on_use = function(self, room, cardUseEvent)
    cardUseEvent.disresponsiveList = table.simpleClone(Fk:currentRoom().players)
    if not cardUseEvent.tos or #cardUseEvent.tos == 0 then
      cardUseEvent.tos = { cardUseEvent.from }
    end
  end,
  on_effect = function(self, room, effect)
    local targets = table.filter(room:getOtherPlayers(effect.to), function(p) return p:getMark("action__fugui") == 0 end)
    local to = room:askToChoosePlayers(effect.to, {
      min_num = 1,
      max_num = 1,
      targets = targets,
      skill_name = self.name,
      cancelable = false,
      prompt = "选择一名其他角色，其下次获得手牌后，你摸等量张牌",
    })
    if #to > 0 then
      room:setPlayerMark(to[1], "action__fugui", effect.to.id)
      room:setPlayerMark(to[1], "@action__fugui", Fk:translate(effect.to.general))
    end
  end,
})


skill:addEffect(fk.AfterCardsMove, {
  mute = true,
  global = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    if player:getMark("action__fugui") ~= 0 and not player.room:getPlayerById(player:getMark("action__fugui")).dead then
      for _, move in ipairs(data) do
        if move.to == player and move.toArea == Card.PlayerHand then
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(player:getMark("action__fugui"))
    local ids = {}
    if to and not to.dead then
      for _, move in ipairs(data) do
        if move.to == player and move.toArea == Card.PlayerHand then
          for _, info in ipairs(move.moveInfo) do
            table.insertIfNeed(ids, info.cardId)
          end
        end
      end
      if #ids > 0 then
        room:drawCards(to, #ids)
      end
      room:setPlayerMark(player, "action__fugui", 0)
    end
    room:setPlayerMark(player, "@action__fugui", 0)
  end,
})


return skill